package com.urbanski.util.logging;

import java.io.PrintStream;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;

public class LoggingUtil
{
	private LoggingUtil()
	{
	}

	public static void logAndPrint(Logger logger, Level level, String message)
	{
		logAndPrint(logger, level, message, System.out);
	}

	public static void logAndPrint(Logger logger, Level level, String message, PrintStream stream)
	{
		logger.log(level, message);
		stream.println(message);
	}

	public static void logAndPrint(Logger logger, Level level, String message, Throwable t)
	{
		logAndPrint(logger, level, message, t, System.err);
	}

	public static void logAndPrint(Logger logger, Level level, String message, Throwable t, PrintStream stream)
	{
		logger.log(level, message, t);
		stream.println(message + ": " + t);
	}

	public static void logAndPrintError(Logger logger, String message)
	{
		logAndPrintError(logger, message, System.err);
	}

	public static void logAndPrintError(Logger logger, String message, PrintStream stream)
	{
		logAndPrint(logger, Level.ERROR, message, stream);
	}

	public static void logAndPrintError(Logger logger, String message, Throwable t)
	{
		logAndPrintError(logger, message, t, System.err);
	}

	public static void logAndPrintError(Logger logger, String message, Throwable t, PrintStream stream)
	{
		logAndPrint(logger, Level.ERROR, message, t, stream);
	}

	public static void logAndPrintWarning(Logger logger, String message)
	{
		logAndPrintWarning(logger, message, System.out);
	}

	public static void logAndPrintWarning(Logger logger, String message, PrintStream stream)
	{
		logAndPrint(logger, Level.WARN, message, stream);
	}

	public static void logAndPrintWarning(Logger logger, String message, Throwable t)
	{
		logAndPrintWarning(logger, message, t, System.out);
	}

	public static void logAndPrintWarning(Logger logger, String message, Throwable t, PrintStream stream)
	{
		logAndPrint(logger, Level.WARN, message, t, stream);
	}

	public static void logAndPrintInfo(Logger logger, String message)
	{
		logAndPrintInfo(logger, message, System.out);
	}

	public static void logAndPrintInfo(Logger logger, String message, PrintStream stream)
	{
		logAndPrint(logger, Level.INFO, message, stream);
	}

	public static void logAndPrintInfo(Logger logger, String message, Throwable t)
	{
		logAndPrintInfo(logger, message, t, System.out);
	}

	public static void logAndPrintInfo(Logger logger, String message, Throwable t, PrintStream stream)
	{
		logAndPrint(logger, Level.INFO, message, t, stream);
	}

	public static void logAndPrintDebug(Logger logger, String message)
	{
		logAndPrintDebug(logger, message, System.out);
	}

	public static void logAndPrintDebug(Logger logger, String message, PrintStream stream)
	{
		logAndPrint(logger, Level.DEBUG, message, stream);
	}

	public static void logAndPrintDebug(Logger logger, String message, Throwable t)
	{
		logAndPrintDebug(logger, message, t, System.out);
	}

	public static void logAndPrintDebug(Logger logger, String message, Throwable t, PrintStream stream)
	{
		logAndPrint(logger, Level.DEBUG, message, t, stream);
	}
}
